﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Manage_Garage_Car.DataAccessLayer;

namespace Manage_Garage_Car.BusinessLogicLayer
{
    class CarBusiness
    {
        #region Fields

        private ConnectData m_connectData = new ConnectData();

        private SqlParameter[] m_sqlParam;

        #endregion

        #region Properties

        public DataTable GetNumberPlate()
        {
            return m_connectData.GetDataTable("GETBIENSO", 0);
        }

        public bool CheckNumberPlate(string _numberPlate)
        {
            m_sqlParam[0] = new SqlParameter("@Check", SqlDbType.Bit);
            m_sqlParam[0].Value = 0;
            m_sqlParam[0].Direction = ParameterDirection.InputOutput;
            m_sqlParam[1] = new SqlParameter("@BienSo", SqlDbType.VarChar, 20);
            m_sqlParam[1].Value = _numberPlate;

            m_sqlParam = m_connectData.GetSqlParam("CHECKBIENSO", 2, m_sqlParam);
            return (bool)m_sqlParam[0].Value;
        }

        public DataTable GetInformationFromNP(string _numberPlate)
        {
            m_sqlParam[0] = new SqlParameter("@BienSo", SqlDbType.VarChar, 20);
            m_sqlParam[0].Value = _numberPlate;
            return m_connectData.GetDataTable("GETINFOMATIONFROMBIENSO", 1, m_sqlParam);
        }

        public DataTable GetDataCar()
        {
            return m_connectData.GetDataTable("LOADXE", 0);
        }

        public bool SetDataCar(string _numberPlate, string _nameCustomer, string _gender,
                               string _nameCarStyle, string _address, string _numberPhone,
                               string _email, double _debit)
        {
            m_sqlParam[0] = new SqlParameter("@BienSo", SqlDbType.VarChar, 20);
            m_sqlParam[0].Value = _numberPlate;
            m_sqlParam[1] = new SqlParameter("@TenKhachHang", SqlDbType.NVarChar, 100);
            m_sqlParam[1].Value = _nameCustomer;
            m_sqlParam[2] = new SqlParameter("@GioiTinh", SqlDbType.NVarChar, 10);
            m_sqlParam[2].Value = _gender;
            m_sqlParam[3] = new SqlParameter("@TenHieuXe", SqlDbType.VarChar, 50);
            m_sqlParam[3].Value = _nameCarStyle;
            m_sqlParam[4] = new SqlParameter("@DiaChi", SqlDbType.NVarChar, 50);
            m_sqlParam[4].Value = _address;
            m_sqlParam[5] = new SqlParameter("@DienThoai", SqlDbType.VarChar, 20);
            m_sqlParam[5].Value = _numberPhone;
            m_sqlParam[6] = new SqlParameter("@Email", SqlDbType.VarChar, 100);
            m_sqlParam[6].Value = _email;
            m_sqlParam[7] = new SqlParameter("@TienNo", SqlDbType.Money);
            m_sqlParam[7].Value = _debit;

            return m_connectData.SetDataTable("ADDXE", 8, m_sqlParam);
        }

        public void FixDataCar(string _numberPlate, string _nameCustomer, string _gender,
                               string _nameCarStyle, string _address, string _numberPhone, string _email)
        {
            m_sqlParam[0] = new SqlParameter("@BienSo", SqlDbType.VarChar, 20);
            m_sqlParam[0].Value = _numberPlate;
            m_sqlParam[1] = new SqlParameter("@TenKhachHang", SqlDbType.NVarChar, 100);
            m_sqlParam[1].Value = _nameCustomer;
            m_sqlParam[2] = new SqlParameter("@GioiTinh", SqlDbType.NVarChar, 10);
            m_sqlParam[2].Value = _gender;
            m_sqlParam[3] = new SqlParameter("@TenHieuXe", SqlDbType.VarChar, 50);
            m_sqlParam[3].Value = _nameCarStyle;
            m_sqlParam[4] = new SqlParameter("@DiaChi", SqlDbType.NVarChar, 50);
            m_sqlParam[4].Value = _address;
            m_sqlParam[5] = new SqlParameter("@DienThoai", SqlDbType.VarChar, 20);
            m_sqlParam[5].Value = _numberPhone;
            m_sqlParam[6] = new SqlParameter("@Email", SqlDbType.VarChar, 100);
            m_sqlParam[6].Value = _email;

            m_connectData.SetDataTable("FIXXE", 7, m_sqlParam);
        }

        public void DeleteDataCar(string _numberPlate)
        {
            m_sqlParam[0] = new SqlParameter("@BienSo", SqlDbType.VarChar, 20);
            m_sqlParam[0].Value = _numberPlate;

            m_connectData.SetDataTable("DELETEXE", 1, m_sqlParam);
        }

        #endregion

        #region Initialization

        public CarBusiness()
        {
            m_connectData = new ConnectData();
            m_sqlParam = new SqlParameter[8];
        }

        #endregion

    }
}
